package com.ccx.coachsite.bus;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import android.view.View;

public class CustomInfo implements Comparable<CustomInfo> {
	private int id;
	private String name;
	private String sex;
	private String customNickName;
	
	private String tianYi;
	private String mode;
	private String packages;
	private String package_gprs;
	private String onlineTime;
	private String joinTime;
	
	private String precinct;
	private String county;
	private String lastMonthAverage_gprs;
	private String state;
	private String average_gprs;
	private int recommend;
	private String gprs_used;
	private String outPackage_gprs;
	private int messageCount;
	private String baseLine;
	private boolean isInvited;
	private String icon;
	private int proportion;
	private String os;
	private View messageBtn;
	private String MessageTime;
	
	public static int SortType = 2;
	
	public String getLastMessageTime()
	{
		if(MessageTime == null || MessageTime.equals("null"))
			return "";
			
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
		//得到指定模范的时间 
		Date d1 = null;
		Date dTmp = null;
		try {
			d1 = sdf.parse(MessageTime);
			dTmp = sdf.parse(MessageTime);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		//Date d1 = new Date(Date.parse(MessageTime));
		if(d1 == null)
			return "";

		Date d2 = new Date(System.currentTimeMillis());
		d1.setHours(0);
		d1.setMinutes(0);
		d1.setSeconds(0);
		d2.setHours(0);
		d2.setMinutes(0);
		d2.setSeconds(0);
		
		long day = Math.abs(((d1.getTime() - d2.getTime())/(24*3600*1000)));
		if( day < 1)
		{
			SimpleDateFormat sdf1 = new SimpleDateFormat("HH:mm"); 
			return sdf1.format(dTmp);
		}
		else if(day == 1)
		{
			return "昨天";
		}
		else if(day < 365)
		{
			SimpleDateFormat sdf1 = new SimpleDateFormat("MM-dd"); 
			return sdf1.format(dTmp);
		}
		else
		{
			SimpleDateFormat sdf1 = new SimpleDateFormat("yyyy-MM-dd"); 
			return sdf1.format(dTmp);
			//return d1.getMonth() + "-" + d1.getDay();
		}
	}
	
	public String getMessageTime() {
		return MessageTime;
	}

	public void setMessageTime(String messageTime) {
		MessageTime = messageTime;
	}
	
	public String getCustomNickName() {
		return customNickName;
	}

	public void setCustomNickName(String customNickName) {
		this.customNickName = customNickName;
	}
	
	public CustomInfo()
	{
		this.package_gprs = "(未知)";
	}
	
	public String getJoinTime() {
		return joinTime;
	}
	public void setJoinTime(String joinTime) {
		this.joinTime = joinTime;
	}
	
	public View getMessageBtn() {
		return messageBtn;
	}
	public void setMessageBtn(View messageBtn) {
		this.messageBtn = messageBtn;
	}
	public String getOs() {
		return os;
	}
	public void setOs(String os) {
		this.os = os;
	}
	public int getProportion() {
		return proportion;
	}
	public void setProportion(int proportion) {
		this.proportion = proportion;
	}
	public String getIcon() {
		return icon;
	}
	public void setIcon(String icon) {
		this.icon = icon;
	}
	private List<AnalysisInfo> analysisList;
	
	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getTianYi() {
		return tianYi;
	}
	public void setTianYi(String tianYi) {
		this.tianYi = tianYi;
	}
	public String getMode() {
		return mode;
	}
	public void setMode(String mode) {
		this.mode = mode;
	}
	public String getPackages() {
		return packages;
	}
	public void setPackages(String packages) {
		this.packages = packages;
	}
	public String getPackage_gprs() {
		return package_gprs;
	}
	public void setPackage_gprs(String package_gprs) {
		this.package_gprs = package_gprs;
	}
	public String getOnlineTime() {
		return onlineTime;
	}
	public void setOnlineTime(String onlineTime) {
		this.onlineTime = onlineTime;
	}
	public String getPrecinct() {
		return precinct;
	}
	public void setPrecinct(String precinct) {
		this.precinct = precinct;
	}
	public String getCounty() {
		return county;
	}
	public void setCounty(String county) {
		this.county = county;
	}
	public String getLastMonthAverage_gprs() {
		return lastMonthAverage_gprs;
	}
	public void setLastMonthAverage_gprs(String lastMonthAverage_gprs) {
		this.lastMonthAverage_gprs = lastMonthAverage_gprs;
	}
	public String getState() {
		return state;
	}
	public void setState(String state) {
		this.state = state;
	}
	public String getAverage_gprs() {
		return average_gprs;
	}
	public void setAverage_gprs(String average_gprs) {
		this.average_gprs = average_gprs;
	}
	public int getRecommend() {
		return recommend;
	}
	public void setRecommend(int recommend) {
		this.recommend = recommend;
	}
	public String getGprs_used() {
		return gprs_used;
	}
	public void setGprs_used(String gprs_used) {
		this.gprs_used = gprs_used;
	}
	public String getOutPackage_gprs() {
		return outPackage_gprs;
	}
	public void setOutPackage_gprs(String outPackage_gprs) {
		this.outPackage_gprs = outPackage_gprs;
	}
	public String getSex() {
		return sex;
	}
	public void setSex(String sex) {
		this.sex = sex;
	}
	public List<AnalysisInfo> getAnalysisList() {
		return analysisList;
	}
	public void setAnalysisList(List<AnalysisInfo> analysisList) {
		this.analysisList = analysisList;
	}
	public String getBaseLine() {
		return baseLine;
	}
	public void setBaseLine(String baseLine) {
		this.baseLine = baseLine;
	}
	public int getMessageCount() {
		return messageCount;
	}
	public void setMessageCount(int messageCount) {
		this.messageCount = messageCount;
	}
	public boolean isInvited() {
		return isInvited;
	}
	public void setInvited(boolean isInvited) {
		this.isInvited = isInvited;
	}
	@Override
	public int compareTo(CustomInfo another) {
		if(SortType == 0)
		{
			if(joinTime == null && another.getJoinTime() == null)
				return 0;
			else if(joinTime != null && another.getJoinTime() == null)
				return 1;
			else if(joinTime == null && another.getJoinTime() != null)
				return -1;
			else 
				return joinTime.compareTo(another.getJoinTime());
		}
		else if(SortType == 1)
		{
			if(baseLine == null && another.getBaseLine() == null)
				return 0;
			else if(baseLine != null && another.getBaseLine() == null)
				return -1;
			else if(baseLine == null && another.getBaseLine() != null)
				return 1;
			else 
			{
				try
				{
					Double d1 = Double.parseDouble(baseLine);
					Double d2 = Double.parseDouble(another.getBaseLine());
					return d2.compareTo(d1);
				}
				catch(Exception e)
				{
					return 0;
				}
				
				
			}
		}
		return 0;
	}
}
